/**
 *
 */
Ext.define('vacake.view.UsersAddress', {
    extend: 'Ext.List',
    xtype: 'usersAddress',
    config: {
        items: [
            {
                docked: 'top',
                xtype: 'toolbar',
                title: '收货地址',
                items: [
                    {
                        text: '返回', ui: 'action-back',
                        handler: function () {
                            Ext.Viewport.remove(this.up('usersAddress'), true);
                        }
                    },
                    { xtype: "spacer" },
                    { text: '新增',
                        handler: function () {
                             Ext.Viewport.animateActiveItem('usersAddressAdd', {type: 'slide', direction: 'left'});
                        }
                    }
                ]
            }
        ],

        store: 'UsersAddress',
        emptyText: '<div style="width: 100%; height: 100%; text-align: center; vertical-align: middle">' +
            '<img width="94" height="94" src="resources/images/null.png" style="margin-top:100px;"   /> ' +
            '<div class="height30 color2 font2">暂时没有设置收货地址</div>' +
            '</div>',
        cls:'x-list1',
        itemTpl:
            "<div style='height:80px; position: relative; width: 80%;'>" +
               "<div class='homelist_name height30 color5 font2'>{name}</div>" +
                "<div class='homelist_name height30 color2 font2'>" +
                    "<span>联系电话：{mobile}</span>" +
                "</div>" +
                "<div class='homelist_name color2 font2'>" +
                    "<span class='height20'>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址：</span>" +
                    "<span style='line-height: 20px;' class='color3'>{address}</span>" +
                "</div>" +
            "</div>",

        onItemDisclosure: {//点击小按钮的时候,触发的事件
            handler: function (record, btn, index, e) {
                e.stopEvent();
                Ext.Msg.confirm('是否删除？', '', function (data) {
                    if (data == 'yes') {
                        Ext.Viewport.mask({
                            xtype: 'loadmask',
                            message: '删除中...'
                        });
                        Ext.Ajax.request({
                            url: Global.api_url + '/cloud/1/shipping_address_delete',
                            params: {
                                csaid: record.get('csaid'),
                                cuid: window.localStorage.getItem('app_Login_id'),
                                cadid: window.localStorage.getItem('app_district_id')
                            },
                            method: 'POST',
                            scope: this,
                            success: function (response) {
                                Ext.Viewport.unmask();
                                var returnText = Ext.decode(response.responseText);
//                                Ext.Msg.alert(returnText.Variables.Message.messagestr);
                                cordova.exec(function (message) {
                                }, function (error) {
                                }, "Messages", "showMsg", [returnText.Variables.Message.messagestr]);
                                if (returnText.Variables.Result.code == 0) {
                                    var usersAddress = Ext.getStore('UsersAddress');
                                    usersAddress.load({params: {cuid: window.localStorage.getItem('app_Login_id'), cadid: window.localStorage.getItem('app_district_id')}});
                                }
                            },
                            failure: function () {//请求失败时执行操作
                                Ext.Viewport.unmask();
                                cordova.exec(function (message) {
                                }, function (error) {
                                }, "Messages", "showMsg", ['请求失败,服务器维护中...']);
//                                Ext.Msg.alert('请求失败', '服务器维护中....');
                            }
                        })
                    }
                }, this);
            }
        },
        listeners: {
            initialize: function () {//当页面初始化前,执行
              
            },
            painted: function () {
                  var usersAddress = Ext.getStore('UsersAddress');
                usersAddress.load({params: {cuid: window.localStorage.getItem('app_Login_id'), cadid: window.localStorage.getItem('app_district_id')}});
                Ext.Viewport.unmask();
            },
            back: function () {
                var backid = Ext.Viewport.getInnerItems().length - 2;
                Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
                Ext.Viewport.setActiveItem(backid);
            }
        }
    }

});

